web/src/pages/[...section].astro

285 lines · 8198 bytes

  1---
  2
  3
  4import Layout from '@layouts/Layout.astro';
  5import Button from '@components/form/Button.astro';
  6import Main from '@components/scafold/MainCard.astro';
  7import ServiceList from '@components/things/ServiceList.astro';
  8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
  9import { fetchData, slugify } from '@utils/fetch-data';
 10import { parseMarkdown } from '@utils/parse-markdown';
 11import { truncate } from '@utils/meta-tags';
 12
 13interface Props {
 14  slug: string,
 15  title: string,
 16  services: Service[],
 17  intro?: string,
 18  notableMentions?: ShortService[] | string,
 19  furtherInfo?: string,
 20  wordOfWarning?: string,
 21  alternativeTo?: string[];
 22  categoryName: string,
 23  otherSections: Section[],
 24}
 25
 26const {
 27  title, otherSections, services, notableMentions, furtherInfo, wordOfWarning,
 28  alternativeTo, categoryName, intro,
 29} = Astro.props;
 30
 31/**
 32 * Make a list of keywords, for the <meta keywords> tag
 33 */
 34const makeKeyWordTag = () => {
 35  const keywords = [];
 36  keywords.push(`free and open source ${title} software`);
 37  keywords.push(`private ${title} comparison`);
 38  (alternativeTo || []).forEach((alt: string) => {
 39    keywords.push(`privacy-respecting ${alt} alternative`);
 40    keywords.push(`free open source ${alt} alternative`);
 41  });
 42  (services || []).forEach((serv: Service) => {
 43    keywords.push(serv.name);
 44  });
 45  keywords.push('ad free');
 46  keywords.push('open source software');
 47  keywords.push('privacy respecting apps');
 48  return keywords.join(', ');
 49};
 50
 51/**
 52 * Make a page title
 53 */
 54const makePageTitle = () => {
 55  return `${title} | Awesome Privacy`;
 56};
 57
 58const makeBreadcrumbs = () => {
 59  return [
 60    { name: 'Home', item: '/' },
 61    { name: categoryName, item: slugify(categoryName) },
 62    { name: title, item: `${slugify(categoryName)}/${slugify(title)}` },
 63  ];
 64};
 65
 66/**
 67 * Make a string page intro, for the description tag
 68 */
 69const makeDescriptionTag = () => {
 70  let description = `Privacy-respecting ${title}. `;
 71  if (services && services.length > 0) {
 72    description += `Compare ${services.map((serv: Service) => serv.name).join(', ')}. `;
 73  } else {
 74    description += `Find private apps and services. This section is still a work in progress. `;
 75  }
 76  if (alternativeTo && alternativeTo.length > 0) {
 77    description += `The best secure, encrypted alternatives to ${alternativeTo.join(', ')}.`;
 78  }
 79  return truncate(description.trim());
 80};
 81
 82const makeCarasolData = () => {
 83  if (!services.length) return undefined;
 84  return {
 85    "@context": "https://schema.org",
 86    "@type": "ItemList",
 87    "itemListElement": services.map((service, index) => ({
 88      "@type": "ListItem",
 89      "position": index + 1,
 90      "url": `https://awesome-privacy.xyz/${slugify(categoryName)}/${slugify(title)}/${slugify(service.name)}/`,
 91      "item": {
 92        "@type": "Service",
 93        "name": service.name,
 94        "description": service.description,
 95        "image": service.icon,
 96        "url": `https://awesome-privacy.xyz/${slugify(categoryName)}/${slugify(title)}/${slugify(service.name)}/`
 97      }
 98    }))
 99  }
100};
101
102export async function getStaticPaths() {
103  const pages = await fetchData().then((data) => {
104    const results: Array<Props> = [];
105    if (!data || !data.categories) return results;
106    (data as AwesomePrivacy).categories.forEach((category) => {
107      const sections = category.sections.map((section) => ({
108        slug: `${slugify(category.name)}/${slugify(section.name)}`,
109        title: section.name,
110        services: section.services,
111        intro: section.intro,
112        notableMentions: section.notableMentions,
113        furtherInfo: section.furtherInfo,
114        wordOfWarning: section.wordOfWarning,
115        alternativeTo: section.alternativeTo,
116        categoryName: category.name,
117        otherSections: category.sections,
118      }));
119      results.push(...sections);
120    });
121    return results;
122  });
123
124  return pages.map((props: Props) => {
125    return {params: { section: props.slug }, props };
126  });
127}
128
129const makePaginationLinks = () => {
130  const index = otherSections.findIndex(section => section.name === title);
131  const previousSection = index >  0 ? otherSections[index -  1].name : null;
132  const nextSection = index < otherSections.length -  1 ? otherSections[index +  1].name : null;
133  return { previous: previousSection, next: nextSection };
134};
135
136const { previous, next } = makePaginationLinks();
137
138---
139
140<Layout
141  title={makePageTitle()}
142  keywords={makeKeyWordTag()}
143  description={makeDescriptionTag()}
144  breadcrumbs={makeBreadcrumbs()}
145  customSchemaJson={makeCarasolData()}
146>
147  <Main>
148
149    <div class="breadcrumbs">
150      <span>
151        <a href="/">Awesome Privacy</a>
152        ➔ <a href={`/${slugify(categoryName)}/`}>{categoryName}</a>
153        ➔ <a href={`/${slugify(categoryName)}/${slugify(title)}/`}>{title}</a>
154      </span>
155    </div>
156
157    <h1>{title}</h1>
158
159    {intro && (
160      <section class="intro">
161        <p set:html={parseMarkdown(intro)}></p>
162      </section>
163    )}
164    
165    <ServiceList services={services} sectionName={title} categoryName={categoryName} />
166
167    <details class="about-this-page">
168      <summary>Objective of this page</summary>
169      <p>
170        Find the best free, open source, E2E encrypted and private alternative to
171        {(alternativeTo || []).map((alt) => (<span>{alt}, </span>))} now.
172      </p>
173      <p>
174        Compare {(services || []).map((serv) => (<span>{serv.name} vs </span>))}
175      </p>
176      <p>
177        Discover the best {title} tools for Android, iPhone, Linux, PC and Chrome to download now.
178        And choose secure, self-hosted, peer-to-peer and independant alternatives
179      </p>
180      <p>
181        <b>Stop the invasion of privacy from big tech, improve data security stay safe.</b>
182      </p>
183    </details>
184
185
186    {notableMentions && (
187      <section class="notable-mentions">
188        <h2>Notable Mentions</h2>
189        { Array.isArray(notableMentions) ?
190          <ul>
191            {notableMentions.map((mention) => (
192              <li>
193                <a href={mention.url}>{mention.name}</a> 
194                {mention.description && (
195                  <span>- </span>
196                  <span set:html={parseMarkdown(mention.description)}></span>
197                )}
198              </li>
199            ))}
200          </ul> :
201          <p set:html={parseMarkdown(notableMentions)}></p>
202      }
203      </section>
204    )}
205
206    {furtherInfo && (
207      <section class="further-info">
208        <h2>Notes</h2>
209        <p set:html={parseMarkdown(furtherInfo)}></p>
210      </section>
211    )}
212
213    {wordOfWarning && (
214      <section class="word-of-warning">
215        <h2>Word of Warning</h2>
216        <p set:html={parseMarkdown(wordOfWarning)}></p>
217      </section>
218    )}
219
220    {services.length > 0 && (<section class="submit-alternative">
221      <h2>Submit New Entry</h2>
222      <p>
223        Are we missing anything?
224        You can help us improve this page, by <a href="/submit/">submitting a new entry</a>
225      </p>
226    </section>
227    )}
228
229    <div class="pagination-navigation">
230      { previous ? (
231        <Button url={`/${slugify(categoryName)}/${slugify(previous)}/`}>
232          <span>← Previous</span>
233          <p>{previous}</p>
234        </Button>
235      ) : <p class="nothing"></p>}
236      <a href={`/${slugify(categoryName)}/`} class="go-to-category">
237        View all in {categoryName} ({otherSections.length})
238      </a>
239      { next && (
240        <Button url={`/${slugify(categoryName)}/${slugify(next)}/`}>
241          <span>Next →</span>
242          <p>{next}</p>
243        </Button>
244      )}
245    </div>
246  </Main>
247</Layout>
248
249<style lang="scss">
250
251section {
252  padding-bottom: var(--space-md);
253  &:not(:last-child) {
254    border-bottom: 2px solid var(--accent-3);
255  }
256}
257
258h1 {
259    font-family: var(--font-subtitle);
260    font-size: var(--text-3xl);
261    margin: -2rem 0 var(--space-lg) -2rem;
262    box-shadow: var(--shadow-lg);
263    background: var(--accent);
264    color: var(--accent-fg);
265    width: fit-content;
266    padding: var(--space-xs) var(--space-sm);
267  }
268
269
270.intro {
271  font-style: italic;
272  opacity: var(--opacity-soft);
273}
274
275
276.about-this-page {
277  summary {
278    display: none;
279  }
280  font-size: var(--text-sm);
281  opacity: var(--opacity-soft);
282}
283
284
285</style>